package servlet;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Timer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.SQLQuery;
import org.hibernate.Transaction;

import client.DateThread;

import server.TCPDesktopServer;
import util.ThreadLocal;

public class MyServlet1 extends HttpServlet{
	private ThreadLocal localObjectInThisThread = new ThreadLocal();
    private static final long serialVersionUID = 1L;
    Timer timer;

    public MyServlet1(){
        timer = new Timer();
    }

    public void init()
        throws ServletException{
    	InetAddress serverAddr;
		try {/*
			System.out.println("client");
			serverAddr = InetAddress.getLocalHost();
			Socket socket = new Socket(serverAddr, 5556);
			Thread t1 = new DateThread(socket,"mac=00-E0-66-8F-3F-39"); 
			 t1.start();
			Thread t2 = new DateThread(socket,"mac=00-E0-66-8F-3F-38"); 
			t2.start();
			Thread t3 = new DateThread(socket,"mac=00-E0-66-8F-3F-37"); 
			 t3.start();
			Thread t4 = new DateThread(socket,"mac=00-E0-66-8F-3F-36"); 
			t4.start();
			Thread t5 = new DateThread(socket,"mac=00-E0-66-8F-3F-35"); 
			 t5.start();
			Thread t6 = new DateThread(socket,"mac=00-E0-66-8F-3F-34"); 
			t6.start();
			Thread t7 = new DateThread(socket,"mac=00-E0-66-8F-3F-33"); 
			 t7.start();
			Thread t8 = new DateThread(socket,"mac=00-E0-66-8F-3F-32"); 
			t8.start();
			Thread t9 = new DateThread(socket,"mac=00-E0-66-8F-3F-31"); 
			 t9.start();
			Thread t10 = new DateThread(socket,"mac=00-E0-66-8F-3F-30"); 
			t10.start();
			Thread t11 = new DateThread(socket,"mac=00-E0-66-8F-3F-29"); 
			 t11.start();
			Thread t12 = new DateThread(socket,"mac=00-E0-66-8F-3F-28"); 
			t12.start();
			Thread t13 = new DateThread(socket,"mac=00-E0-66-8F-3F-27"); 
			 t13.start();
			Thread t14 = new DateThread(socket,"mac=00-E0-66-8F-3F-26"); 
			t14.start();
			Thread t15 = new DateThread(socket,"mac=00-E0-66-8F-3F-25"); 
			 t15.start();
			Thread t16 = new DateThread(socket,"mac=00-E0-66-8F-3F-24"); 
			t16.start();
			Thread t17 = new DateThread(socket,"mac=00-E0-66-8F-3F-23"); 
			 t17.start();
			Thread t18 = new DateThread(socket,"mac=00-E0-66-8F-3F-22"); 
			t18.start();
			Thread t19 = new DateThread(socket,"mac=00-E0-66-8F-3F-21"); 
			 t19.start();
			Thread t20 = new DateThread(socket,"mac=00-E0-66-8F-3F-20"); 
			t20.start();
			Thread t21 = new DateThread(socket,"mac=00-E0-66-8F-3F-19"); 
			 t21.start();
			Thread t22 = new DateThread(socket,"mac=00-E0-66-8F-3F-18"); 
			t22.start();
			
			
			Thread t23 = new DateThread(socket,"mac=00-E0-66-8F-3F-17"); 
			 t23.start();
			Thread t24 = new DateThread(socket,"mac=00-E0-66-8F-3F-16"); 
			t24.start();
			Thread t25 = new DateThread(socket,"mac=00-E0-66-8F-3F-15"); 
			 t25.start();*/
			 System.out.println("client——end");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
    }
		/*localObjectInThisThread.set(HibernateSessionFactory.getSession());
		doSomething();
    }
    public void doSomething()
    {
      org.hibernate.Session thisThreadsSession = (HibernateUtil.getSessionFactory().getCurrentSession())

      localObjectInThisThread.get();
      
     //基于当前session的存取操作
      Transaction tx=thisThreadsSession.beginTransaction();
      String sql="INSERT INTO tHistory20131001(id,mark,hData,deviceId)  VALUES('9208582a1ba84e238c9cdd909d7e75f7',0,'3.7','test55555')";
      SQLQuery query = thisThreadsSession.createSQLQuery(sql);
      query.executeUpdate();
      tx.commit();
      thisThreadsSession.flush();
    }*/
    public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException{
    }

    public void destory(){
        timer.cancel();
    }
}
